package cn.com.ajava.util;

import gnu.xml.dom.DomNode;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class DomDemo {

	public static void getGitProjectPath() 
	{
		try {
			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder dbBuilder = dbFactory.newDocumentBuilder();
			Document doc = dbBuilder.parse(new File(System.getProperty("user.dir")+"/src/default.xml"));
			NodeList rootTags = doc.getElementsByTagName("manifest");
			
			String base = " git clone https://android.googlesource.com/";
			String suffix = ".git";
			for (int i = 0; i < rootTags.getLength(); i++) 
			{
				Element rootNode = (Element) rootTags.item(i);
				NodeList childNodeList = rootNode.getChildNodes();
				for (int j = 0; j < childNodeList.getLength(); j++) 
				{
					DomNode node = (DomNode) childNodeList.item(j);
					if("project".equals(node.getNodeName()))
					{
						System.out.println(base +node.getAttributes().getNamedItem("name").getNodeValue()+suffix );
					}
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	public static void main(String[] args)
	{
		getGitProjectPath();
	}
}